import { observable, action, toJS } from 'mobx';
import { message } from 'antd';
import * as request from '../../apis/plan/planBasicSettingApi'
import { WeaLocaleProvider,WeaTools} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
export default class PlanBaseStroe{

    @observable loading = false;

    @observable frontOrBackOptions = []
    frontOrBackMap = {};
    //页面的所有输入参数
    @observable formParams={
        isweek:1,  //是否开启周报
        ismonth:1,  //是否开启月报

        wstarttype:1,  //周开始类型 -1前1后
        wstartdays:0,  //周开始天数
        wendtype:1,//周结束时间
        wenddays:0,//周结束天数
        iswremind:1,//是否提醒

        mstarttype:1,//月开始类型 -1前1后
        mstartdays:0,//同上
        mendtype:1,
        menddays:0,
        ismremind:1,

        programcreate:'',  //制定人
        programcreatename:"", 
        reportaudit:'', //审核人
        reportauditname:"",
        reportview:'',//查看人
        reportviewname:"",
        docsecid:'',//附件目录
        docpath:'',
        ismanager:'',//上级定义
        isself:'',//个人定义
        manageraudit:'',//直接上级审批
        subcompanyids:'',//应用到其他分部
        departmentids:'',//应用到其他部门
        resourceids:'',//应用到其他人力
        operation:'' 
    };

    @observable weekRowData ={};
    @observable monthRowData = {};

    @observable tableDataList=[];

    @observable canedit = false; //能不能编辑
    @observable candel = false; //能不能删除
    titlename = "";

    @observable treeNodeData={ //树选择的数据
        resourcetype:'',
        resourceid:'',
        resourcename:''
    }
    emptydata =[];
    @observable canfresh = false;

    @action("设置form属性")
    setFormParams=(param,value)=>{
        this.formParams[param]=value;
    }

    @action("获取属性")
    getFormParams() {
        return this.formParams;
    }

    @action("获取基础设置数据")
    getBasicSetting = (params) => {
        this.loading = true;
        this.canfresh = false;
        request.getBasicSetting(params).then(action(res=>{
            if(res.api_status){
                this.titlename = res.titlename;
                this.emptydata = [];
                this.canedit = res.canedit;
                this.candel=res.canDel;
                this.formParams = res.formParams;
            }else{
                message.error(res.msg || getLabel('383746','请求失败') );
            }
            this.canfresh = true;
            this.loading=false;
        }));
    }

    @action("操作")
    basicSettingOperation = (params) => {
        this.loading = true;
        request.basicSettingOperation(params).then(action(res=>{
            if(res.api_status){
                if(res.hasRight){
                    message.success(getLabel('30700','操作成功') );
                    this.getBasicSetting({resourceid:this.treeNodeData.resourceid,resourcetype:this.treeNodeData.resourcetype});
                }else{
                    message.error(getLabel('386358','您没有权限！') );
                }
            }else{
                message.error(res.msg || getLabel('383746','请求失败') );
            }
            this.loading = false;
        }));
    }
    
  //获取日期类型
  @action('getOption')
  getOption = ()=>{
      WeaTools.callApi('/api/workrelate/plan/getOption', 'GET', {type:2}).then(
        action(res=>{
          if(res.api_status){
            this.frontOrBackOptions=res.data;
            this.frontOrBackMap = res.datamap;
          }else{
            message.error (res.msg || getLabel('383746','请求失败') );
          }
        })
      )
  }
}